//
//  WelcomeViewController.swift
//  Meboo
//
//  Created by kyo on 2024/4/12.
//

import UIKit
import Lottie

class WelcomeViewController: BaseSwiftViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        makeUI()
    }
    
    
    // MARK:  - Private Method
    func resetRootView() {
        let appDelegate = UIApplication.shared.delegate as? AppDelegate
        if account != nil {
            appDelegate?.window?.rootViewController = BaseTabBarViewController.init()
        } else {
            appDelegate?.window?.rootViewController = BaseNavViewController.init(rootViewController: KLLoginViewController.init())
        }
    }
    
    // MARK:  - UI
    private func makeUI() {
        self.view.addSubview(lottieView)
    }
    
    
    // MARK:  - Setter && Getter
    /// lottieView
    lazy var lottieView: LottieAnimationView = {
        let view = LottieAnimationView.init(frame: self.view.bounds)
        view.loopMode = .playOnce
        view.contentMode = .scaleAspectFill
        view.animation = animation
        view.play { completed in
            view.removeFromSuperview()
            if completed {
                self.resetRootView()
            }
        }
        return view
    }()
    
    ///animation
    lazy var animation: LottieAnimation = {
        let  animation = LottieAnimation.named("launchVideo.json",animationCache: DefaultAnimationCache.sharedCache)
        return animation!
    }()
    
    ///animation
    lazy var account: MBUserAccount? = {
        let  account = MBUserAccount.default()
        return account
    }()

}
